﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TermSetting.aspx.cs" Inherits="Education_TermSetting" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>学年学期设置</title>
    
    <link href="../Common/css/main.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #load{width:500px;height:25px;border:1px #000 solid;}
        #loading{position:absolute;z-index:2;height:23;filter:progid:DXImageTransform.microsoft.gradient(gradienttype=1,startColorStr=white,endColorStr=#39867b);}
        #loadtext{position:absolute;z-index:3;width:100%;height:100%;line-height:23px;text-align:center;}
    </style>
    
    <script type="text/javascript" src="../Common/Js/jquery.js"></script>

    <script type="text/javascript" src="../Common/Js/common.js"></script>

    <script type="text/javascript" src="../Common/Js/msg.js"></script>

    <script type="text/javascript" src="../Common/Js/jsUtil.js"></script>

    <script type="text/javascript" src="../Common/js/My97DatePicker/WdatePicker.js"></script>
    
    <script type="text/javascript">

var rid = 0;
function ConvertDate(date) {
    var year = 0;
    var month = 0;
    var day = 0;
    var strDate = "";
    
    year = date.getYear();
    month = date.getMonth()+1;
    day = date.getDate();
    strDate = year +"-"+month+"-"+day;
    return strDate;
}


function Load()
{
    rid = 0;
    var selectYear = document.getElementById('selectYear');
    
    //清空
    while(selectYear.options.length)
    {
        selectYear.options.remove(0);
    }

    //初始化学年下拉框
    var years = ['2003 - 2004学年', '2004 - 2005学年', '2005 - 2006学年', '2006 - 2007学年', '2007 - 2008学年', '2008 - 2009学年', '2009 - 2010学年',
                 '2010 - 2011学年', '2011 - 2012学年', '2012 - 2013学年', '2013 - 2014学年', '2014 - 2015学年', '2015 - 2016学年', '2016 - 2017学年', 
                 '2017 - 2018学年', '2018 - 2019学年', '2019 - 2020学年', '2020 - 2021学年'];
    for(var i = 0; i < years.length;i++)
    {
        var oOption = document.createElement("OPTION");
        oOption.text=years[i];
        oOption.value=2003+i;
        selectYear.add(oOption);
    }
    
    var nowYear = GetNowYear();
    if (nowYear>2020 || nowYear<2003)
        selectYear.value = 2003;
    else
        selectYear.value = nowYear;
    
    //获取数据
    PageMethods.GetGloblTermInfo(function(succ){
        if(succ != null)
        {
            changeStatus(1);
            //只读状态，只能升级
            rid = succ.RID;
            document.getElementById('txtYear').setAttribute("number", succ.SchoolYear);
            document.getElementById('txtTerm').setAttribute("number", succ.Term);
            document.getElementById('txtYear').value = succ.SchoolYear + " - " + (succ.SchoolYear+1) + "学年";
            document.getElementById('txtTerm').value = succ.Term;
            document.getElementById('txtStart').value = ConvertDate(succ.StartDate);
            document.getElementById('txtEnd').value = succ.EndDate == null ? "未指定" : ConvertDate(succ.EndDate);
            
            if (succ.Term == 1)
                document.getElementById('txtTerm').value = '上学期';
            else if (succ.Term == 2)
                document.getElementById('txtTerm').value = '下学期';
        }
        else
        {
            //alert('');
            //可修改状态，向数据库里添加数据
            changeStatus(0);
        }
        
    },function(err){//异步失败
        showMassgeBox("提示","获取全局学期信息失败，请刷新重试",1,null);
    });
}

//保存
function Save()
{        
    var year = document.getElementById('selectYear').value.Trim();
    var term = document.getElementById('selectTerm').value.Trim();
    
    var globlTermInfo = {RID:rid,GlobalYear:year,GlobalTerm:term};
    
    
    PageMethods.UpdateGloblTermInfo(globlTermInfo, function(succ){
        if(succ > 0)
        {
            //最初设置学年学期，保存记录ID
            if (rid == 0) rid = succ;
            
            showMassgeBox("提示","设置全局学期信息设置成功",1,null);  
            Load();     
        }
    },function(err){//异步失败
        showMassgeBox("提示","设置全局学期信息失败，请刷新重试",1,null);
    });
}

function UpgradeTermBtnClick()
{
    //showConfirmBox("升级", "确定进行学期升级吗？", UpgradeTerm, 0); 
    ShowPopForm("termSetting", "termSettingTitle", "学期升级设置");
}

//升级学期
function UpgradeTerm(obj)
{
    var year = document.getElementById('txtYear').getAttribute("number");
    var term = document.getElementById('txtTerm').getAttribute("number");
    
    if (term == 1)
    {
        year = year;
        term = 2;
    }
    else if (term == 2)
    {
    
        year = parseInt( year)+1;
        term = 1;
    }
    
    var startDate = document.getElementById("txtStartDate").value;
    var endDate = document.getElementById("txtEndDate").value;
    if(startDate == null || startDate.length < 1) {
        showMassgeBox("提示","请设定学期开始日期",1,null);
        return;
    }
    
    var globlTermInfo = {RID:rid,GlobalYear:year,GlobalTerm:term};
    PageMethods.UpdateGloblTermInfo(globlTermInfo, startDate, endDate,
     function(succ){
        if(succ > 0)
        {
            //最初设置学年学期，保存记录ID
            if (rid == 0) rid = succ;
            
            showMassgeBox("提示","设置全局学期信息设置成功",1,null);  
            Load();     
            ClosePopForm('termSetting');
        }
    },function(err){//异步失败
        showMassgeBox("提示","设置全局学期信息失败，请刷新重试",1,null);
    });
}

function changeStatus(value)
{
    //保存状态
    if (value == 0)
    {
        document.getElementById('selectYear').style.display = "";
        document.getElementById('selectTerm').style.display = "";
        document.getElementById('txtYear').style.display = "none";
        document.getElementById('txtTerm').style.display = "none";
        document.getElementById('btnSave').style.display = "";
        document.getElementById('btnUpgrade').style.display = "none";
    }
    //升级状态
    if (value == 1)
    {
        document.getElementById('selectYear').style.display = "none";
        document.getElementById('selectTerm').style.display = "none";
        document.getElementById('txtYear').style.display = "";
        document.getElementById('txtTerm').style.display = "";
        document.getElementById('btnSave').style.display = "none";
        document.getElementById('btnUpgrade').style.display = "";
    }
}
    </script>
    
</head>
<body onload="Load();">
    <div class="mainWarp">
        <div class="pageBody" style="text-align: center">
            <form id="form1" runat="server">
            <table style="margin-top:15%;border: #c3dce5 solid;">
                <tr>
                <td>
                  <table style="width: 360px; height:180px; margin-top:15%; text-align:center;" 
                        border="0" class="layoutTable">
                        <tr>
                            <td>
                                当前学年：&nbsp;
                                <select id="selectYear" style='width: 120px; display: none;'>
                                </select>
                                <input id="txtYear" type="text" class='txtStyle' readonly='true' style='display: none;' />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                当前学期：&nbsp;
                                <select id="selectTerm" style='width: 120px; display: none;'>
                                    <option value="1" selected>上学期</option>
                                    <option value="2">下学期</option>
                                </select>
                                <input id="txtTerm" type="text" class='txtStyle' readonly='true' style='display: none;' />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                学期开始：&nbsp;
                                <input id="txtStart" type="text" class='txtStyle' readonly='true'/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                学期结束：&nbsp;
                                <input id="txtEnd" type="text" class='txtStyle' readonly='true'/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="text-align:center;">
                                <div style="width:70%;text-align:left;">
                            　　    说明：学期升级功能用来设置全局的学年和学期，其他系统均会引用该设置，请谨慎操作。
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="button" id="btnSave" value="保存" onclick="Save();" class="commonBut"
                                    style='display: none;' />
                                <input type="button" id="btnUpgrade" value="学期升级" onclick="UpgradeTermBtnClick();" class="commonBut"
                                    style='display: none;' />
                            </td>
                        </tr>
                    </table>
                    </td>
                    </tr>
                </table>
                <div>
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                    </asp:ScriptManager>
                </div>
                
                <!-- 学期设置 -->
                <div id="termSetting" class="layoutWarp" style="display: none; width: 340px; height: 168px;">
                    <div class="title">
                        <span id="termSettingTitle"></span><a title="关闭" onclick="ClosePopForm('termSetting');">
                            关闭</a>
                    </div>
                    <table border="0" class="layoutTable" style="width:300px; height: 120px;">
                        <tr>
                            <td>
                                <span style="color:Red;">* </span><span>学期开始日期: </span>
                            </td>
                            <td>
                                <input readonly="readonly" maxlength="20" name="text" type="text" class="txtStyle" id="txtStartDate" onfocus="WdatePicker({skin:'whyGreenSmall',dateFmt:'yyyy/MM/dd'})"/>
                                
                            </td>
                        </tr>
                        <tr>
                        <td>
                                <span>&nbsp;&nbsp;学期截止日期: </span>
                        </td>
                            <td>
                                <input readonly="readonly" maxlength="20" name="text" type="text" class="txtStyle" id="txtEndDate" onfocus="WdatePicker({skin:'whyGreenSmall',dateFmt:'yyyy/MM/dd'})"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div style="text-align:center;">
                                    <input type="button" class="commonBut" id="btnTermSettingOK"
                                        onclick="UpgradeTerm(0);" value="确定" />
                                    <input type="button" class="commonBut" id="btnTermSettingCacel"
                                        onclick="ClosePopForm('termSetting');" value="取消" />
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <!-- END -->

            </form>
        </div>
    </div>
</body>
</html>
